//
//  LBSpringAnimationController.m
//  TEXT
//
//  Created by mac on 2025/1/10.
//  Copyright © 2025 刘博. All rights reserved.
//

#import "LBSpringAnimationController.h"

@interface LBSpringAnimationController ()

@property (nonatomic, strong)UIView *animationView;

@end

@implementation LBSpringAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"normalAnimation" forState:UIControlStateNormal];
    button.frame = CGRectMake(100, 80, 150, 40);
    [button addTarget:self action:@selector(normalAnimation) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.backgroundColor = [UIColor cyanColor];
    
    
    UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
    secondButton.frame = CGRectMake(100,150, 150, 40);
    secondButton.backgroundColor = [UIColor redColor];
    secondButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [secondButton setTitle:@"springAnimation" forState:UIControlStateNormal];
    [secondButton addTarget:self action:@selector(springAnimation) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:secondButton];
    
    [self.view addSubview:self.animationView];
    // Do any additional setup after loading the view.
}


- (void)normalAnimation
{
    [UIView animateWithDuration:1 animations:^{
        self.animationView.frame = CGRectMake(10, 400, 50, 50);
    } completion:^(BOOL finished) {
        self.animationView.frame = CGRectMake(10, 100, 50, 50);
    }];
}

- (void)springAnimation
{
    [UIView animateWithDuration:1
                          delay:0
         usingSpringWithDamping:1
          initialSpringVelocity:0
                        options:UIViewAnimationOptionCurveLinear
                     animations:^{
        self.animationView.frame = CGRectMake(10, 400, 50, 50);
    } completion:^(BOOL finished) {
        self.animationView.frame = CGRectMake(10, 100, 50, 50);

    }];
}

#pragma mark - lazy load

- (UIView *)animationView
{
    if (!_animationView) {
        _animationView = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 50, 50)];
        _animationView.backgroundColor = [UIColor greenColor];
    }
    return _animationView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
